package com.zhihuichongcheng.application.ui.main.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.base.BaseFragment;
import com.zhihuichongcheng.application.ui.approval.activity.ApprovalChooseActivity;
import com.zhihuichongcheng.application.ui.approval.activity.ApprovalListActivity;
import com.zhihuichongcheng.application.ui.mine.UserInfoActivity;

/**
 * Created by 3water on 2016/11/1.
 */

public class ApprovalCopyFragment extends BaseFragment implements View.OnClickListener {
    private ImageView mImUser;
    private RelativeLayout mRlWaittingApproval, mRlAlreadyApproval, mRlMyApproval, mRlSendTome, mRlSendApproval, mSaveApproval;
    private TextView mTvWaittingApprovalUnread, mTvUnApproval, mTvRejectApprovalUnread;

    @Override
    protected void init() {
        super.init();
        initView();
        initData();
    }

    private void initView() {
        mImUser = (ImageView) mView.findViewById(R.id.im_user);
        mRlWaittingApproval = (RelativeLayout) mView.findViewById(R.id.rl_waitting_approval);
        mRlAlreadyApproval = (RelativeLayout) mView.findViewById(R.id.rl_already_approval);
        mRlMyApproval = (RelativeLayout) mView.findViewById(R.id.rl_my_approval);
        mRlSendTome = (RelativeLayout) mView.findViewById(R.id.rl_send_tome);
        mRlSendApproval = (RelativeLayout) mView.findViewById(R.id.rl_send_approval);
        mSaveApproval = (RelativeLayout) mView.findViewById(R.id.rl_save_approval);
        mTvWaittingApprovalUnread = (TextView) mView.findViewById(R.id.tv_waitting_approval_unread);
        mTvRejectApprovalUnread = (TextView) mView.findViewById(R.id.tv_waitting_reject_unread);
        mTvUnApproval = (TextView) mView.findViewById(R.id.tv_unApproval);
        mImUser.setOnClickListener(this);
        mRlWaittingApproval.setOnClickListener(this);
        mRlAlreadyApproval.setOnClickListener(this);
        mRlMyApproval.setOnClickListener(this);
        mRlSendTome.setOnClickListener(this);
        mRlSendApproval.setOnClickListener(this);
        mSaveApproval.setOnClickListener(this);
    }

    private void initData() {
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_approval_copy;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_waitting_approval:
                //待我审批
                Bundle bundle = new Bundle();
                bundle.putInt("type", 0);
                bundle.putString("title", "待我审批");
                spUtil.putInt("waitCount", 0);
                startActivity(ApprovalListActivity.class, bundle);
                break;
            case R.id.rl_already_approval:
                //我已审批
                bundle = new Bundle();
                bundle.putInt("type", 1);
                bundle.putString("title", "我已审批");
                startActivity(ApprovalListActivity.class, bundle);
                break;
            case R.id.rl_my_approval:
                //我发起的
                bundle = new Bundle();
                bundle.putInt("type", 2);
                bundle.putString("title", "我发起的");
                startActivity(ApprovalListActivity.class, bundle);

                break;
            case R.id.rl_send_tome:
                //抄送给我的
                bundle = new Bundle();
                bundle.putInt("type", 3);
                bundle.putString("title", "抄送我的");
                startActivity(ApprovalListActivity.class, bundle);
                break;
            case R.id.rl_send_approval:
                //发起审批
                startActivity(ApprovalChooseActivity.class, null);
                break;
            case R.id.rl_save_approval:
                bundle = new Bundle();
                bundle.putInt("type", 4);
                bundle.putString("title", "已保存审批");
                startActivity(ApprovalListActivity.class, bundle);
                break;
            case R.id.im_user:
                startActivity(UserInfoActivity.class, null);
                break;
            default:
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        reflush();
    }

    @SuppressLint("WrongConstant")
    public void reflush() {
        int size = spUtil.getInt("waitCount");
        if (size > 0) {
            mTvWaittingApprovalUnread.setText(size + "条待办");
            mTvWaittingApprovalUnread.setVisibility(View.VISIBLE);
        } else {
            mTvWaittingApprovalUnread.setVisibility(View.GONE);
        }
        int size2 = spUtil.getInt("rejectCount");
        if (size2 > 0) {
            mTvRejectApprovalUnread.setText(size2 + "条驳回");
            mTvRejectApprovalUnread.setVisibility(View.VISIBLE);
        } else {
            mTvRejectApprovalUnread.setVisibility(View.GONE);
        }

    }
}
